home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.09 Sep 91 / Bug Parser Code / Mini.print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-25  |  2.8 KB  |  139 lines  |  [TEXT/KAHL]

  1. /*********************************************************************
  2.  
  3.     mini.print.c
  4.     
  5.     printing functions for Miniedit
  6.     
  7. *********************************************************************/
  8.  
  9. #include <MacTypes.h>
  10. #include <QuickDraw.h>
  11. #include <PrintTraps.h>
  12.  
  13. #define topMargin 20
  14. #define leftMargin 20
  15. #define bottomMargin 20
  16.  
  17. #define NIL 0L
  18.  
  19. static    THPrint    hPrint = NIL;
  20. static    int        tabWidth;
  21.  
  22. CheckPrintHandle()
  23. {
  24.     if (hPrint==NIL) 
  25.         PrintDefault(hPrint = (TPrint **) NewHandle( sizeof( TPrint )));
  26. }
  27.  
  28. DoPageSetUp()
  29. {
  30.     PrOpen();
  31.     CheckPrintHandle();
  32.     if (PrStlDialog(hPrint)) ;
  33.     PrClose();
  34. }
  35.  
  36. #define tabChar    ((char)'\t')
  37.  
  38. MyDrawText(p, count)
  39. char    *p;
  40. int        count;
  41. {
  42.     register char    *p1, *p2;
  43.     int                len;
  44.     Point            pt;
  45.  
  46.     p1 = p;
  47.     p2 = p+count;
  48.     while (p<p2) {
  49.         while ((p1<p2) && (*p1 !=tabChar)) *p1++;
  50.         if ((len=p1-p)>0) DrawText( p, 0, p1-p );
  51.         if (*p1==tabChar) {
  52.             GetPen(&pt);
  53.             Move((tabWidth-(pt.h-leftMargin)%tabWidth), 0);
  54.             *p1++;
  55.         }
  56.         p = p1;
  57.     }
  58. }
  59.  
  60. PrDoc(hText, count, hPrint, font, size)
  61. char        **hText;
  62. long        count;
  63. THPrint     hPrint;
  64. int            font;
  65. int            size;
  66. {
  67.     register int     line = 0;
  68.     register int     lastLineOnPage = 0;
  69.     int                length;
  70.     Rect             printRect;
  71.     int             linesPerPage;
  72.     int             lineBase;
  73.     int             lineHeight;
  74.     register char     *ptr, *p1;
  75.     FontInfo        info;
  76.     TPPrPort        printPort;
  77.  
  78.     printPort = PrOpenDoc( hPrint, 0L, 0L );
  79.     SetPort(printPort);
  80.     TextFont(font);
  81.     TextSize(size);
  82.     printRect = (**hPrint).prInfo.rPage;
  83.     GetFontInfo( &info );
  84.     lineHeight = info.leading+info.ascent+info.descent;
  85.     linesPerPage = 
  86.         (printRect.bottom-printRect.top-topMargin-bottomMargin)/lineHeight;
  87.     HLock(hText);
  88.     ptr = p1 = (*hText);
  89.     do {
  90.         PrOpenPage( printPort, 0L );
  91.         lastLineOnPage += linesPerPage;
  92.         MoveTo( printRect.left+leftMargin, 
  93.             (lineBase = printRect.top+lineHeight) );
  94.         do {
  95.             /* PrintLine: */
  96.             while ((ptr<=(*hText)+count) && (*ptr++ != (char)'\r')) ;
  97.             if ((length=(int)(ptr-p1)-1)>0) MyDrawText(p1, length);
  98.             MoveTo( printRect.left+leftMargin, (lineBase += lineHeight));
  99.             p1 = ptr;
  100.         } while ((++line != lastLineOnPage) && (ptr<(*hText)+count));
  101.         PrClosePage( printPort );
  102.     } while (ptr<(*hText)+count);
  103.     HUnlock(hText);
  104.     PrCloseDoc( printPort );
  105. }
  106.  
  107. PrintText(hText, length, gp, tabPixels)
  108. char    **hText;
  109. long    length;
  110. GrafPtr    gp;
  111. int        tabPixels;
  112. {
  113.     TPPrPort    printPort;
  114.     GrafPtr        savePort;
  115.     TPrStatus    prStatus;
  116.     int            copies;
  117.     
  118.     PrOpen();
  119.     CheckPrintHandle();
  120.     tabWidth = tabPixels;
  121.     SetCursor( &arrow );
  122.     if (PrJobDialog(hPrint) != 0) {
  123.         PleaseWait();
  124.         GetPort(&savePort);
  125.         for (copies=HowMany(); copies>0; copies--) {
  126.             PrDoc (hText, length, hPrint, (*gp).txFont, (*gp).txSize);
  127.             PrPicFile( hPrint, 0L, 0L, 0L, &prStatus );
  128.         }
  129.         SetPort(savePort);
  130.     }
  131.     PrClose();
  132. }
  133.  
  134. HowMany()
  135. {
  136.     return( ((**hPrint).prJob.bJDocLoop==bDraftLoop) ? 
  137.                 (**hPrint).prJob.iCopies : 1 );
  138. }
  139.